<script>
import userApi from "@/api/user.js";
import { getGlobalData } from "@/utils/request/appFn.js";
export default {
  onLaunch: function (r) {
    uni.hideTabBar(); // 默认隐藏原生tabbar,使用自定义底部
    // console.log('小程序 信息 ：' + JSON.stringify(uni.getAccountInfoSync()))
    getGlobalData() // 获取设备信息
    // console.log('App Launch',r)
  },
  onShow: function () {
    // console.log("App Show");
    if ((uni.getStorageSync('token')&&this.$store.state.token)&&(uni.getStorageSync('token')==this.$store.state.token)) return
    let _this = this
    wx.checkSession({
      async success () {
        let token = uni.getStorageSync('token')
        let userInfo = uni.getStorageSync('userInfo')
        if(token){ // 有token
          _this.$store.commit('TOKEN', token)
          if(!userInfo && !userInfo.nickname){ // 无用户信息
            userApi.getInfo().then(async (res_) => {
              _this.$store.commit("USERINFO", res_.data)
            })
          }else{ // 存在用户信息
            _this.$store.commit("USERINFO", userInfo)
          }
        }
      },
      fail () {
        _this.$store.commit('TOKEN', '')
        uni.setStorageSync('token', '')
      }
    })
  },
  onHide: function () {
    console.log("App Hide");
  },
};
</script>
<style lang="scss">
/*每个页面公共css */
@import "./styles/common.scss";
@import "./styles/custom.scss";
@import "./styles/iconfont.scss";
@import "uview-ui/index.scss";
</style>
